<template>
    <j-modal
      :width="modalWidth"
      :visible="visible"
      :title="title"
      switchFullscreen
      @ok="handleSubmit"
      @cancel="close"
      style="top: 50px"
      cancelText="关闭"
    >
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="员工编号">
                  <j-input placeholder="请输入员工编号" v-model="queryParam.employeeCode"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="员工姓名">
                  <j-input placeholder="请输入员工姓名" v-model="queryParam.employeeName"></j-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
          >项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>
        <div>
          <a-table
            ref="table"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: checkval }"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
            :customRow="customClick"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>
          </a-table>
        </div>
      </a-card>
    </j-modal>
  </template>
  
  <script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { filterObj } from '@/utils/util'
  import { deleteAction, getAction, httpAction } from '@api/manage'
  
  export default {
    name: 'EmployeeListModal',
    mixins: [JeecgListMixin, mixinDevice],
    components: {},
    props: {
      category: {
        type: String,
      },
      modalWidth: {
        type: Number,
        required: false,
        default: 1250,
      },
      checkval: {
        type: String,
        default: 'radio',
      },
      supplierId: {
        type: String,
        required: false,
      },
    },
    data() {
      return {
        visible: false,
        title: '选择员工',
        description: '人员信息表',
        activeKey: 'on',
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '50'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '员工编号',
            align: 'center',
            sorter: true,
            fixed: 'left',
            dataIndex: 'employeeCode',
          },
          {
            title: '员工姓名',
            align: 'center',
            sorter: true,
            fixed: 'left',
            dataIndex: 'employeeName',
          },
          {
            title: '所属部门',
            align: 'center',
            sorter: true,
            fixed: 'left',
            dataIndex: 'departCode_dictText',
          },
          {
            title: '岗位',
            align: 'center',
            dataIndex: 'post_dictText',
          },
          {
            title: '籍贯',
            align: 'center',
            dataIndex: 'birthplace',
          },
          {
            title: '婚姻状况',
            align: 'center',
            dataIndex: 'marriageStatus_dictText',
          },
          {
            title: '曾用名',
            align: 'center',
            dataIndex: 'previousName',
          },
          {
            title: '性别',
            align: 'center',
            sorter: true,
            dataIndex: 'sex_dictText',
          },
          {
            title: '民族',
            align: 'center',
            dataIndex: 'nation',
          },
          {
            title: '年龄',
            align: 'center',
            dataIndex: 'age',
          },
          {
            title: '出生日期',
            align: 'center',
            dataIndex: 'birthDate',
            customRender: function (text) {
              return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
          },
  
          {
            title: '身份证号',
            align: 'center',
            dataIndex: 'idCard',
          },
          {
            title: '家庭住址',
            align: 'center',
            dataIndex: 'address',
          },
          {
            title: '户口所在地',
            align: 'center',
            dataIndex: 'registerLocation',
          },
          {
            title: '手机号',
            align: 'center',
            dataIndex: 'telephone',
          },
          {
            title: '电子邮件',
            align: 'center',
            dataIndex: 'email',
          },
          {
            title: '学历',
            align: 'center',
            dataIndex: 'educationBackground_dictText',
          },
          {
            title: '毕业院校',
            align: 'center',
            dataIndex: 'graduatedFrom',
          },
          {
            title: '专业',
            align: 'center',
            dataIndex: 'major',
          },
          {
            title: '职务',
            align: 'center',
            dataIndex: 'duties',
          },
  
          {
            title: '入职时间',
            align: 'center',
            dataIndex: 'entryDate',
            customRender: function (text) {
              return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
          },
          {
            title: '合同类型',
            align: 'center',
            dataIndex: 'contractType_dictText',
          },
          {
            title: '合同开始日期',
            align: 'center',
            dataIndex: 'contractStartDate',
            customRender: function (text) {
              return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
          },
          {
            title: '合同终止日期',
            align: 'center',
            dataIndex: 'contractEndDate',
            customRender: function (text) {
              return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
            },
          },
          {
            title: '证书取得',
            align: 'center',
            dataIndex: 'certificates',
          },
          {
            title: '工作经历',
            align: 'center',
            dataIndex: 'workExperience',
          },
          {
            title: '学习经历',
            align: 'center',
            dataIndex: 'educationExperience',
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
          },
        ],
        url: {
          list: '/hr/tslHrEmployeeInfo/list',
        },
        dictOptions: {},
        superFieldList: [],
      }
    },
    created() {
      this.loadData()
      this.getSuperFieldList()
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      },
    },
    methods: {
      close() {
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectionRows = []
        this.visible = false
      },
      add() {
        this.showModal()
      },
      showModal() {
        this.dataSource = []
        this.visible = true
        this.loadData()
      },
      handleSubmit() {
        this.getSelectRows()
        // this.searchReset(false)
        this.queryParam = {}
        this.onClearSelected()
        this.close()
      },
      getSelectRows() {
        let selectedRow = null
        if (this.checkval == 'radio') {
          selectedRow = this.selectionRows[0]
        } else {
          selectedRow = this.selectionRows
        }
        //传递选中的数据
        this.$emit('selectFinished', selectedRow)
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
      },
      modalFormOk() {
        this.loadData()
      },
      loadData() {
        var params = this.getQueryParams()
        console.log(params, 'loadDATA')
        params.status = '1'
        this.loading = true
        getAction(this.url.list, params)
          .then((res) => {
            if (res.success) {
              //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
              this.dataSource = res.result.records || res.result
              if (res.result.total) {
                this.ipagination.total = res.result.total
              } else {
                this.ipagination.total = 0
              }
              //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({ type: 'sel_depart', value: 'departCode', text: '所属部门' })
        fieldList.push({ type: 'string', value: 'employeeCode', text: '员工编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'employeeName', text: '员工姓名', dictCode: '' })
        fieldList.push({ type: 'string', value: 'birthplace', text: '籍贯', dictCode: '' })
        fieldList.push({ type: 'int', value: 'marriageStatus', text: '婚姻状况', dictCode: 'marriage_status' })
        fieldList.push({ type: 'string', value: 'previousName', text: '曾用名', dictCode: '' })
        fieldList.push({ type: 'int', value: 'sex', text: '性别', dictCode: 'sex' })
        fieldList.push({ type: 'string', value: 'nation', text: '民族', dictCode: '' })
        fieldList.push({ type: 'int', value: 'age', text: '年龄', dictCode: '' })
        fieldList.push({ type: 'date', value: 'birthDate', text: '出生日期' })
        fieldList.push({ type: 'string', value: 'idCard', text: '身份证号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'address', text: '家庭住址', dictCode: '' })
        fieldList.push({ type: 'string', value: 'registerLocation', text: '户口所在地', dictCode: '' })
        fieldList.push({ type: 'string', value: 'telephone', text: '手机号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'qqCode', text: 'QQ', dictCode: '' })
        fieldList.push({ type: 'string', value: 'email', text: '电子邮件', dictCode: '' })
        fieldList.push({ type: 'string', value: 'officeCall', text: '办公电话', dictCode: '' })
        fieldList.push({ type: 'int', value: 'educationBackground', text: '学历', dictCode: 'education_background' })
        fieldList.push({ type: 'string', value: 'graduatedFrom', text: '毕业院校', dictCode: '' })
        fieldList.push({ type: 'string', value: 'major', text: '专业', dictCode: '' })
        fieldList.push({ type: 'string', value: 'duties', text: '职务', dictCode: '' })
        fieldList.push({ type: 'string', value: 'post', text: '岗位', dictCode: '' })
        fieldList.push({ type: 'date', value: 'firstJobDate', text: '参加工作时间' })
        fieldList.push({ type: 'date', value: 'entryDate', text: '入职时间' })
        fieldList.push({ type: 'int', value: 'contractType', text: '合同类型', dictCode: 'employee_contract_type' })
        fieldList.push({ type: 'date', value: 'contractStartDate', text: '合同开始日期' })
        fieldList.push({ type: 'date', value: 'contractEndDate', text: '合同终止日期' })
        fieldList.push({ type: 'string', value: 'socialInsurance', text: '保险说明', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'fixedSalary', text: '固定工资', dictCode: '' })
        fieldList.push({ type: 'BigDecimal', value: 'performanceSalary', text: '绩效工资', dictCode: '' })
        fieldList.push({ type: 'string', value: 'attenceCode', text: '考勤编号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'bankCardCode', text: '银行卡号', dictCode: '' })
        fieldList.push({ type: 'date', value: 'insuranceDate', text: '公司参保时间' })
        fieldList.push({ type: 'int', value: 'insuranceType', text: '参保类型', dictCode: 'insurance_type' })
        fieldList.push({ type: 'string', value: 'fileCode', text: '档案号', dictCode: '' })
        fieldList.push({ type: 'string', value: 'photo', text: '照片', dictCode: '' })
        fieldList.push({ type: 'int', value: 'accident', text: '意外', dictCode: 'accident_pay' })
        fieldList.push({ type: 'int', value: 'riskPay', text: '风险金', dictCode: 'risk_pay' })
        fieldList.push({ type: 'BigDecimal', value: 'seniorityWage', text: '工龄工资', dictCode: '' })
        fieldList.push({ type: 'string', value: 'attachment', text: '附件列表', dictCode: '' })
        fieldList.push({ type: 'string', value: 'certificates', text: '证书取得', dictCode: '' })
        fieldList.push({ type: 'string', value: 'workExperience', text: '工作经历', dictCode: '' })
        fieldList.push({ type: 'string', value: 'educationExperience', text: '学习经历', dictCode: '' })
        fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
        fieldList.push({ type: 'date', value: 'leaveDate', text: '离职日期' })
        fieldList.push({ type: 'string', value: 'leaveReason', text: '离职原因', dictCode: '' })
        fieldList.push({ type: 'string', value: 'leaveDepart', text: '离职部门', dictCode: '' })
        this.superFieldList = fieldList
      },
      customClick(record) {
        var that = this;
        return {
          on: {
            dblclick: () => {
              that.$emit('selectFinished', record)
              that.queryParam = {}
              that.onClearSelected()
              that.close()
            },
          },
        }
      },
    },
  }
  </script>
  <style scoped>
  @import '~@assets/less/common.less';
  </style>
  